猴子请来的救兵 2018-01-17 21:00:32

镜像

获取镜像

Docker 的镜像基本都存在它的官方仓库中『 https://hub.docker.com 』,可以使用『docker search』命令来搜索你想要的镜像是否存在

# 如果没有配置国内的镜像源,它默认会去 "https://hub.docker.com" 去找是否有合适的镜像
docker search centos

------------------------------------------------------------------------------------------
NAME                               DESCRIPTION                                     STARS    
centos                             The official build of CentOS.                   3966     
ansible/centos7-ansible            Ansible on Centos7                              103      
jdeathe/centos-ssh                 CentOS-6 6.9 x86_64 / CentOS-7 7.4.1708 x86_…   91       
consol/centos-xfce-vnc             Centos container with "headless" VNC session…   42       
imagine10255/centos6-lnmp-php56    centos6-lnmp-php56                              37
...

还是可以使用更高级的搜索方式

# 仅显示自动创建的镜像
docker search --automated=false centos

# 搜索指定评价为多少颗星星的镜像
docker search --stars=0 centos

下载镜像

搜索到了自己想要的镜像,就可以使用『docker pull』命令从仓库中来获取镜像

# 从官方仓库获取镜像
docker pull centos

# 获取指定版本镜像
docker pull centos:6.9

# 获取指定的镜像
docker pull imagine10255/centos6-lnmp-php56

# 从指定仓库获取镜像
docker pull [host:port]/centos

查看镜像

使用『docker images』命令来查看镜像

# 查看本地已经存在的镜像
docker images

------------------------------------------------------------------------------------------
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              f9b6f7f7b9d3        3 days ago          1.14MB
registry            latest              d1fd7d86a825        9 days ago          33.3MB
centos              latest              ff426288ea90        10 days ago         207MB
influxdb            latest              3b6c470bec0e        5 weeks ago         198MB
redis               latest              1e70071f4af4        5 weeks ago         107MB
mysql               latest              7d83a47ab2d2        5 weeks ago         408MB

镜像详情

使用『docker inspect』来查看镜像的详细信息,会返回一个它的『json』格式的明细,记录的重要的数据。

# 查看镜像详细信息
docker inspect [img_id]

# 查看镜像详细信息的个别值
docker inspect -f {{".Architecture"}} [img_id]

删除镜像

如果你的镜像不想用了,或者不好用了,想要删除它,可以使用『docker rmi』来删除本地镜像

# 删除镜像
docker rmi [img_id]

# 强制删除镜像
docker rmi -f [img_id]

镜像保存

如果你做了高质量的镜像,可以使用『docker save』来保存镜像。方便下次换了机器,或者环境变了的时候,重新导入该镜像

# 默认保存在你执行命令的当前路径,如果想要指定路径,需要在镜像名前面加上路径即可
docker save -o [img_name.tar] [img]

镜像导入

使用『docker load』来导入镜像

docker load --input [img_name.tar]